package com.xiyue.leaspring.datasourceTest;

import java.util.Date;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.xiyue.leaspring.service.INewsService;
import com.xiyue.leaspring.vo.News;

@ContextConfiguration(locations = {"classpath:spring/spring-jdbc10.xml"})
@RunWith(SpringJUnit4ClassRunner.class)//设置要测试的工具
public class DataSourceTest11 {
	
	@Autowired
	private INewsService newsService;
		
	/**
	 * 通过主键查询
	 * @throws Exception
	 */
	@Test
	public void testFindById() throws Exception {
		
		System.out.println(this.newsService.get(1L));
		System.out.println(this.newsService.get(1L));
		
	}
	
	@Test
	public void testEidt() throws Exception{
		System.out.println(this.newsService.get(1L));//查询指定编号数据，进行缓存
		News vo = new News();
		vo.setNid(1L);
		vo.setTitle("撒旦wqe");
		vo.setNote("时间即qwe完事万物皆对象");
		vo.setPrice(12823.12);
		vo.setPubDate(new Date());
		vo.setReadCount(1412);
		this.newsService.edit(vo);//更新缓存中的数据
		System.out.println(this.newsService.get(1L));//获取更新后的内容
		
	}
	
	@Test
	public void testDelete() throws Exception {
		System.out.println(this.newsService.get(2L));//指定缓存数据
		this.newsService.delete(2L);//删除指定编号新闻,并且清楚缓存
		System.out.println(this.newsService.get(2L));//此时将无法获取缓存信息
	}
	
}
